package org.grottarossa.ui.core.container;


import java.io.Serializable;
import java.util.ArrayList;
import java.util.ResourceBundle;

import org.grottarossa.template.data.enums.EnumDataType;
import org.grottarossa.template.data.pojo.history.History;
import org.grottarossa.template.data.pojo.history.HistoryList;
import org.grottarossa.template.data.pojo.table.Cell;
import org.grottarossa.template.data.pojo.table.Record;
import org.grottarossa.template.data.pojo.table.Table;
import org.grottarossa.ui.core.i18n.DM;

import com.vaadin.data.util.HierarchicalContainer;

public class HistoryContainer extends TableContainer
{
	private static final long serialVersionUID = 1L;

	private static ResourceBundle m_localizer = DM.instance().getBundle(HistoryContainer.class.getName());

	public String MODIFIEDBY = m_localizer.getString("container.columns.modifiedby");
	public String BODY = m_localizer.getString("container.columns.body");
	public String MODIFIEDDATE = m_localizer.getString("container.columns.modifieddate");

	private String [] m_visibleColumns = { MODIFIEDBY, BODY, MODIFIEDDATE };

	public HistoryContainer(HistoryList historyList)
	{
		super();
		setHistories(historyList);
	}

	private void createTableHeader(Table data)
	{
		data.getHeader().add(new Cell(EnumDataType.String, MODIFIEDBY));
		data.getHeader().add(new Cell(EnumDataType.String, BODY));
		data.getHeader().add(new Cell(EnumDataType.Calendar, MODIFIEDDATE));
	}

	public void setHistories(HistoryList historyList)
	{
		Table data = new Table();
		createTableHeader(data);

		for( History history : historyList)
		{
			Record r = new Record();

			r.add(new Cell(EnumDataType.String, history.getModifiedBy()));
			r.add(new Cell(EnumDataType.String, history.getBody()));
			r.add(new Cell(EnumDataType.Calendar, history.getModifiedDateTime()));

			data.getRecords().add(r);
		}

		setDataTable(data);
	}

	public String[] getVisibleColumns()
	{
		return m_visibleColumns;
	}
}
